package com.javakc.mes.basis.area.controller;

import com.javakc.mes.basis.area.entity.Area;
import com.javakc.mes.basis.area.service.AreaService;
import com.javakc.mes.basis.roadway.entity.Roadway;
import com.javakc.mes.basis.section.entity.Section;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Api("矿井采区接口")
@RestController
@RequestMapping("mes/basis/area")
public class AreaController {

    @Autowired
    private AreaService areaService;

    /**
     * 查询所有采区
     * @return 查询到的所有的采区
     */
    @GetMapping
    @ApiOperation("查询所有数据")
    public List<Area> queryAll(){
        return areaService.queryAll();
    }

    /**
     * 单条查询  查询单个采区 以及下属的工作面和巷道
     * @param id 路径参数,采区的id
     * @return 采取数据以及下属的工作面和巷道
     */
    @GetMapping("{id}")
    public Map<String,Object> query(@PathVariable int id){
        Area area = areaService.getById(id);
//        List<Section> sectionList = area.getSectionList();
//        List<Roadway> roadwayList = area.getRoadwayList();
        Map<String,Object> result=new HashMap<>();
        result.put("area",area);
//        result.put("section",sectionList);
//        result.put("roadway",roadwayList);
        return result;
    }


    @PutMapping
    public void update(@RequestBody Area area){
        areaService.saveOrUpdate(area);
    }

    @PostMapping
    public void save(@RequestBody Area area){
        areaService.saveOrUpdate(area);
    }

    @DeleteMapping("{id}")
    public void delete(@PathVariable int id){
        areaService.removeById(id);

    }

}
